package com.example.dellpc.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;

import com.karumi.expandableselector.ExpandableItem;
import com.karumi.expandableselector.ExpandableSelector;
import com.karumi.expandableselector.OnExpandableItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 刘智强 on 2016/8/16.
 */
public class MyExpandableSelector extends Activity {
    private ExpandableSelector expandableSelector,expandableSelector_image;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.expandableselector);
        initView();
    }

    public void initView() {
        expandableSelector = (ExpandableSelector) findViewById(R.id.es);
        List<ExpandableItem> expandableItems = new ArrayList<>();
        expandableItems.add(new ExpandableItem("XL"));
        expandableItems.add(new ExpandableItem("L"));
        expandableItems.add(new ExpandableItem("M"));
        expandableItems.add(new ExpandableItem("S"));
        expandableSelector.showExpandableItems(expandableItems);
        expandableSelector.setOnExpandableItemClickListener(new OnExpandableItemClickListener() {
            @Override
            public void onExpandableItemClickListener(int index, View view) {

                switch (index) {
                    case 0:
                        expandableSelector.collapse(); //折叠

                        break;
                    case 1:
                        expandableSelector.collapse();

                        break;
                    case 2:
                        expandableSelector.collapse();
                        break;
                    case 3:
                        expandableSelector.collapse();
                        break;


                    default:

                }

            }
        });

        expandableSelector_image= (ExpandableSelector) findViewById(R.id.es_image);
        List<ExpandableItem> expandableItemList=new ArrayList<>();
        expandableItemList.add(new ExpandableItem(R.mipmap.ic_launcher));
        expandableItemList.add(new ExpandableItem(R.mipmap.ic_launcher));
        expandableItemList.add(new ExpandableItem(R.mipmap.ic_launcher));
        expandableItemList.add(new ExpandableItem(R.mipmap.ic_launcher));
        expandableItemList.add(new ExpandableItem(R.mipmap.ic_launcher));
        expandableSelector_image.showExpandableItems(expandableItemList);
        expandableSelector_image.setOnExpandableItemClickListener(new OnExpandableItemClickListener() {
            @Override
            public void onExpandableItemClickListener(int index, View view) {
                switch (index) {
                    case 0:
                        expandableSelector_image.collapse(); //折叠
                        break;
                    case 1:
                        expandableSelector_image.collapse();

                        break;
                    case 2:
                        expandableSelector_image.collapse();
                        break;
                    case 3:
                        expandableSelector_image.collapse();
                        break;
                    case 4:
                        expandableSelector_image.collapse();
                        break;


                    default:

                }


            }
        });



    }
}
